package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.RequestTagSO;

@Entity
@Table(name = "REQUEST_TAG", uniqueConstraints = @UniqueConstraint(columnNames = { "TAG_ID", "REQUEST_ID" }))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class RequestTag extends AbstractBaseModel {
	
	private static final long serialVersionUID = 1L;
    
	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "TAG_ID", nullable = false)
    private Tag tag;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "REQUEST_ID", nullable = false)
	private Request request;

	public Tag getTag() {
		return tag;
	}

	public void setTag(Tag tag) {
		this.tag = tag;
	}

	public Request getRequest() {
		return request;
	}

	public void setRequest(Request request) {
		this.request = request;
	}

	@Override
	public String toString() {
		return "OfferTag [tag=" + tag + ", request=" + request + "]";
	}

	public RequestTagSO convertToServiceObject() {
		RequestTagSO so = (RequestTagSO) convert(new RequestTagSO());
		so.setRequest(this.request.convertToServiceObject());
		so.setTag(this.tag.convertToServiceObject());
		return so;
	}

	
}
